#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>

char* const addenv[] = {
     (char* const)"MYVAL1=123456789",
     (char* const)"MYVAL2=123456789",
     (char* const)"MYVAL3=123456789",
     NULL 
};

int main()
{
    printf("我的程序要运行了!\n");

    if(fork() == 0)
    {
        printf("I am Child, My Pid Is: %d\n", getpid());
        sleep(1);

        char *const argv[] = {
            (char *const)"other",
            (char *const)"-a",
            (char *const)"-b",
            (char *const)"-c",
            (char *const)"-d",
            NULL
        };

       // char* const env[] = {
       //     (char* const)"MYVAL=123456789",
       //     NULL 
       // };

       // execvpe("./other", argv, env);
       
        for(int i = 0; addenv[i]; ++i)
        {
            putenv(addenv[i]);
        }
       
        extern char** environ;
        execvpe("./other", argv, environ);
    }
    
    waitpid(-1, NULL, 0);
    printf("我的程序运行完毕了\n");

    return 0;
}
